package com.ssh.service.impl;

import java.util.List;
import java.util.Objects;

import com.ssh.dao.NativePlaceDao;
import com.ssh.dao.impl.NativePlaceDaoImpl;
import com.ssh.model.NativePlace;
import com.ssh.service.NativePlaceService;

public class NativePlaceServiceImpl implements NativePlaceService{

	private NativePlaceDao nativePlaceDao=new NativePlaceDaoImpl();
	
	@Override 
	public List<NativePlace> getProvince() {
		return nativePlaceDao.getLevel1();
	}

	@Override
	public List<NativePlace> getCity(String code) {
		return nativePlaceDao.getLevel2(code);
	}

	@Override
	public List<NativePlace> setProvinceSelected(String code) {
		List<NativePlace> list=nativePlaceDao.getLevel1();
		String provinceCode=code.substring(0,2);
		list.stream().filter((item)->Objects.equals(item.getCode(),provinceCode)).forEach((item)->item.setSelected(true));
		return list;
	}

	@Override
	public List<NativePlace> setCitySelected(String code) {
		List<NativePlace> list=nativePlaceDao.getLevel2(code.substring(0, 2));
		list.stream().filter((item)->Objects.equals(item.getCode(),code)).forEach((item)->item.setSelected(true));
		return list;
	}
}
